package org.interfaceadaptation.parameter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.interfaceadaptation.parameter.expression.Context;
import org.interfaceadaptation.parameter.expression.Expression;
import org.interfaceadaptation.parameter.expression.impl.Root;

public class Parameter implements Expression {

    private List<String> names = new ArrayList<String>();
    private Root root;
    private Parameter associated;

    public Parameter(Class<?> type, String paramName, String ... extraNames) {
        this.names.add(paramName);
        this.names.addAll(Arrays.asList(extraNames));
        this.root = new Root(type);
    }
    
    public Parameter(Class<?> type, List<String> names) {
        this.names = new ArrayList<String>(names);
        this.root = new Root(type);
    }


    public List<String> getNames() {
        return Collections.unmodifiableList(names);
    }

    @Override
    public Object getValue(Context context) {
        return root.getValue(context);
    }

    @Override
    public void setValue(Context context, Object value) {
        root.setValue(context, value);
    }

    @Override
    public Class<?> getReturnType() {
        return root.getReturnType();
    }

    @Override
    public Class<?> getGenericReturnType() {
        return root.getGenericReturnType();
    }

    @Override
    public String getDefaultNodeName() {
        return names.get(0);
    }

    @Override
    public String getPath() {
        return root.getPath();
    }

    @Override
    public Parameter getParent() {
        return null;
    }
    
    public String toString() {
        return names.get(0);
    }
    
    public void setAssociated(Parameter associated) {
        this.associated = associated;
    }
    
    public Parameter getAssociated() {
        return associated;
    }

    @Override
    public List<String> getAllNodeNames() {
        return Collections.unmodifiableList(names);
    }

}
